import React, { Component } from 'react';
import { Form, Select, Input, Icon, Upload, Button, Modal, message } from 'antd';
const FormItem = Form.Item;
const Option = Select.Option;
const { TextArea } = Input;

class PopForm1 extends Component {
  constructor(props) {
    super(props);
    this.state = {

    };
  }
  normFile = (e) => {
    if (Array.isArray(e)) {
      return e;
    }
    return e && e.fileList;
  }
  render() {
    const { visible, onCancel, onCreate } = this.props;
    const { getFieldDecorator } = this.props.form;
    const Token = sessionStorage.getItem('token');
    const $this = this;
    const props2 = {
      action: '/api/admin/blockchaincode/upload',
      accept: '.go',
      listType: 'text',
      headers: {
        Authorization: Token
      },
      disabled: $this.state.disabledUpload,
      className: 'upload-list-inline',
      onChange(info) {
        if (info.file.status === 'done' && info.file.response.code === '200') {
          // $this.setState({
          //   upload: info.file.response.data.url,
          //   disabledUpload: true,
          //   errorValue: true,
          // });
          message.success('上传成功！');
        } else if (info.file.status === 'error') {
          // message.error('上传失败！');
        }
        console.log(info);
        $this.setState({
          fileList: [info.file]
        });
      }
    };
    return (
      <Modal
        visible={visible}
        title="新增Chaincode模板"
        okText="确定"
        cancelText="取消"
        onCancel={onCancel}
        onOk={onCreate.bind(this, this)}
        destroyOnClose
      >
        <Form>
          <FormItem
            label="name"
            labelCol={{ span: 5 }}
            wrapperCol={{ span: 16 }}
          >
            {getFieldDecorator('name', {
              rules: [{ required: true, message: '请输入请输入ChaincodeName!', }],
            })(
              <Input placeholder="请输入请输入ChaincodeName" />
            )}
          </FormItem>
          <FormItem
            label="模板描述："
            labelCol={{ span: 5 }}
            wrapperCol={{ span: 16 }}
          >
            {getFieldDecorator('description', {
              rules: [{ required: true, message: '请输入内容!', }],
            })(
              <TextArea rows={4} />
            )}
          </FormItem>
          <FormItem
            label="Path："
            labelCol={{ span: 5 }}
            wrapperCol={{ span: 16 }}
          >
            {getFieldDecorator('upload', {
              valuePropName: 'fileList',
              getValueFromEvent: $this.normFile,
              rules: [{ required: true, message: '请上传go文件!', }],
            })(
              <Upload {...props2}>
                <Button>
                  <Icon type="upload" /> 上传
                </Button>
              </Upload>
            )}
          </FormItem>
        </Form>
      </Modal>
    );
  }

}
const AddForm = Form.create()(PopForm1);
export default AddForm;